<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<style>
<!--
.h10{
	height: 10px;
}
-->
.headImg{
	height:5em;
	width:5em;
}
</style>
	<div class="m-b-md">
		<div class="h10"></div>
		<form class="form-inline" role="form" id="searchForm" name="searchForm">
			<div class="form-group">
				<label class="control-label">
				<span>礼品名称:</span></label>
				<input class="form-control" id="name" qt="like" name="commodityFormMap.name">
			</div>
			<div class="form-group">
				<label class="control-label">
				<span>礼品属性:</span></label>
				<input class="form-control" id="porperty" qt="like" name="commodityFormMap.property">
			</div>
			<div class="form-group">
				<label class="control-label">
				<span>礼品详情:</span></label>
				<input class="form-control" id="description" qt="like" name="commodityFormMap.description">
			</div>
			<a href="javascript:void(0)" class="btn btn-default" id="search">查询</a>
		</form>
	</div>
	<header class="panel-heading">
	<div class="doc-buttons">
		<c:forEach items="${res}" var="key">
			${key.description}
		</c:forEach>
	</div>
	</header>
	<div class="table-responsive">
		<div id="paging" class="pagclass"></div>
	</div>
	
<script type="text/javascript">

var dict = [];
<c:forEach items="${dict }" var="record">
dict.push({'value':'${record.value}','label':'${record.label}'});
</c:forEach>

var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "id",
			name : "编辑",
			width : "55px",
			renderData : function(rowindex,data, rowdata, column) {
				return "<img class='imgbtn' title='编辑' src='" + rootPath + "/images/edit.png' onclick=\"editFun('"+data+"')\"/>";
			}
		}, {
			colkey : "images",
			name : "礼品图片",
			renderData: function(rowindex,data, rowdata, column) {
				return "<img src='" + rootPath + "/upload/images/"+data+"' class='headImg'/>";
			}
		},{
			colkey : "name",
			name : "礼品名称",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		}, {
			colkey : "property",
			name : "礼品属性",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		}, {
			colkey : "description",
			name : "礼品详情",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		}, {
			colkey : "integralPrice",
			name : "积分数值",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		}, {
			colkey : "money",
			name : "商品价格",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		}, {
			colkey : "accountName",
			name : "操作人",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+data+"'>"+data+"</span>";
			}
		},{
			colkey : "createTime",
			name : "创建时间",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+new Date(data).format("yyyy-MM-dd hh:mm:ss")+"'>"+new Date(data).format("yyyy-MM-dd hh:mm:ss")+"</span>";
			}
		},{
			colkey : "updateTime",
			name : "修改时间",
			renderData : function(rowindex,data, rowdata, column) {
				return "<span title='"+new Date(data).format("yyyy-MM-dd hh:mm:ss")+"'>"+new Date(data).format("yyyy-MM-dd hh:mm:ss")+"</span>";
			}
		}],
		jsonUrl : rootPath + '/commdoity/findCommodityByPage.shtml',
		checkbox : true
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		$("input[qt=like]").each(function() {
			if ($(this).val().trim() != "") {
				searchParams[$(this).attr("name")] = "%" + $(this).val().trim() + "%";
			}
		});
		grid.setOptions({
			data : searchParams
		});
	});
	$("#addFun").click("click", function() {
		addFun();
	});
	$("#editFun").click("click", function() {
		editFun();
	});
	$("#delFun").click("click", function() {
		delFun();
	});
});
function editFun(cbox) {
	pageii = layer.open({
		title : "编辑",
		type : 2,
		area : [ "600px", "530px" ],
		content : [ rootPath + '/commdoity/editUI.shtml?id=' + cbox, 'no']
	});
}
function addFun() {
	pageii = layer.open({
		title : "新增",
		type : 2,
		area : [ "600px", "530px" ],
		content : [ rootPath + '/commdoity/editUI.shtml', 'no']
	});
}
function delFun() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/commdoity/deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}
</script>